from langchain_core.prompts import ChatPromptTemplate,FewShotChatMessagePromptTemplate

# 定义示例数据，用于少样本学习
examples = [
    {"input":"1x2", "output":"2"},
    {"input":"2x2", "output":"4"}
]
# 创建示例提示模板，安义人类提问和AI回答的交互格式
example_prompt = ChatPromptTemplate.from_messages([
    ("human", "{input}是多少"),
    ("ai", "{output}")
])
# 创建少量样本聊天消息提示模板
few_shot_prompt = FewShotChatMessagePromptTemplate(
    examples=examples,
    example_prompt=example_prompt
)

# 构建最终的提示模板
final_prompt = ChatPromptTemplate.from_messages([
    ("system","你是一名百年一遇的数学奇才")
]) + few_shot_prompt + ChatPromptTemplate.from_messages([
    ("human", "{question}")
])
# 格式化并打印
print(final_prompt.format(question="1x3是多少"))